define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
    	index: function () {
    		var myChart = echarts.init(document.getElementById("echarts-map-world"));
		    var ajax_page=function(memo){
		    	var overtime='<tr><td colspan="7" style="text-align:center;">请求超时，<a href="javascript:;" class="ajax-page" data-memo="'+memo+'">点击重试</a></td></tr>';
		        $.ajax({
		            url:url,
		            type:'post',
		            data:'memo='+memo,
		            dataType: "json",
		            timeout: '10000',
		            beforeSend:function(){
		                $(".btn-group .btn-primary").addClass("btn-default");
		                $(".btn-group .btn-primary").removeClass("btn-primary");
		                $("#"+memo).addClass("btn-primary");
		                $("#"+memo).removeClass("btn-default");
		                $('.visit-world-tbody').html('<tr><td colspan="7" style="text-align: center;"><span><i class="fa fa-spin fa-spinner" aria-hidden="true"></i>&nbsp;&nbsp;数据获取中...<span></td></tr>');
		            },
		            success:function(res){
		                if(res.status){
		                    var map=res.map;
		                    var option = {
		                        tooltip : {
		                            trigger: 'item',
		                        },
		                        nameMap:nameMap,
		                        visualMap: {
		                            min:'0',
		                            max:map[0]['value'],
		                            left: 'left',
		                            top: 'bottom',
		                            orient: 'horizontal',
		                            inverse:true,
		                            align:'left',
		                            inRange: {
		                                color: ['rgba(230,230,230,0.6)', '#3385e3'],
		                                symbolSize: [30, 100]
		                            },
		                            outRange: {
		                                color: ['#e6e6e6', '#3385e3'],
		                                symbolSize: [30, 100]
		                            },
		                            borderColor:'#ffffff',
		                            text:['高','低'],
		                        },
		                        series : [
		                            {
		                                name: '浏览量(PV)',
		                                type: 'map',
		                                map: 'world',
		                                roam: true,
		                                label: {
		                                    normal: {
		                                        show: false
		                                    },
		                                    emphasis: {
		                                        show: true
		                                    }
		                                },
		                                itemStyle:{
		                                    normal:{
		                                        borderColor:'#ffffff',
		                                        areaColor:'#e6e6e6'
		                                    }
		                                },
		                                data:map
		                            },
		                        ]
		                    };
		                    myChart.setOption(option);
		                    $('.pv_count').html(res['sum'][0]);
		                    $('.visitor_count').html(res['sum'][1]);
		                    $('.ip_count').html(res['sum'][2]);
		                    $('.bounce_ratio').html(res['sum'][3]+'%');
		                    $('.avg_visit_time').html(res['sum'][4]);
		                    $('.visit-world-tbody').html(res.html);
		                }else{
		                    $('.visit-world-tbody').html('<tr><td colspan="7" style="text-align:center;">'+res.msg+'</td></tr>');
		                }
		            },
		            error:function(XMLHttpRequest, textStatus, errorThrown){
		                $('.visit-world-tbody').html(overtime); 
		            },
		            complete: function (XMLHttpRequest, textStatus) {
		                if(textStatus == 'timeout'){
		                    $('.visit-world-tbody').html(overtime);
		                }
		            },
		        });
		    };
		    
		    if(bdtj_show==1){
				ajax_page('tody');
			}else{
				layer.alert("尚未配置，请前往插件管理-百度网站统计-配置");
			}
		    $(document).on("click",".ajax-page",function(){
		    	var memo=$(this).attr("data-memo");
		    	ajax_page(memo);
		    })
    	}
    };
    return Controller;
});